import scrapy
from CatEye.items import CateyeItem

class CateyeSpider(scrapy.Spider):
    name = 'cateye'
    allowed_domains = ['www.maoyan.com']
    start_urls = ['http://www.maoyan.com/board/4?offset=0']
    offset = 0

    def parse(self, response):
        dd_list=response.xpath('//dl[@class="board-wrapper"]/dd')
        item=CatEyeItem()
        for dd in dd_list:
            item['name']=dd.xpath('./a/@title').get().strip()
            item['star']=dd.xpath('.//p[@class="star"]/text()').get().strip()
            item['time']=dd.xpath('.//p[@class="releasetime"]/text()').get().strip()
            yield item
        if self.offset < 90:
            self.offset += 10
            url = 'https://maoyan.com/board/4?offset='+str(self.offset)
            yield scrapy.Request(url=url,callback=self.parse)
